package com.wxp.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	
	/**
	 * 
	 * @param cal
	 * @returnss
	 */
	public static String formatToString(Calendar cal,String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String str = sdf.format(cal.getTime());
		return str;
	}
	
	public static Date getDate() {
		Calendar cal = Calendar.getInstance();
		return cal.getTime();
	}

	/**
	 * 日期转换为Long类型
	 * @param str
	 * @return
	 */
	public static Long getDateByLong(String str)
	{
		if (str != null && str.length() > 0)
		{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			try {
				Date date = sdf.parse(str);
				return date.getTime();
			} catch (ParseException e) {
				e.printStackTrace();
				return null;
			}
		}
		return null;

	}

}
